/*
 *  Copyright 2015-2016, RenGu Technology (BeiJing) Co., Ltd.
 *  All right reserved.
 *
 *  THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF RENGU TECHNOLOGY (BeiJing) CO., LTD.
 *
 *  THE CONTENTS OF THIS FILE MAY NOT BE DISCLOSED TO THIR PARTIES,
 *  COPIED OR DUPLICATED IN ANY FORM, IN WHOLE OR IN PART,
 *  WITHOUT THE PRIOR WRITTEN PERMISSION OF RENGU TECHNOLOGY (BeiJing) CO., LTD.
 *
 *  VirtAcctServiceImpl
 *
 *  Edit History:
 *      lizhangtao Created on 2020年04月09日
 *
 */
package cc.rengu.igas.acct.biz.service.impl;

import cc.rengu.igas.acct.common.enums.AcctRespCodeEnum;
import cc.rengu.igas.acct.common.enums.AcctTxnNumEnum;
import cc.rengu.igas.acct.facade.VirtAcctService;
import cc.rengu.igas.acct.facade.request.*;
import cc.rengu.igas.acct.facade.response.*;
import cc.rengu.igas.acct.facade.result.Result;
import cc.rengu.oltp.service.common.enums.OltpRpcdEnum;
import cc.rengu.oltp.service.model.BizException;
import cc.rengu.oltp.service.model.DubboResult;
import cc.rengu.oltp.service.realize.DubboService;
import cc.rengu.oltp.service.realize.impl.DubboServiceImpl;

/**
 * 虚拟账户服务实现
 *
 * @author lizhangtao
 * @version 1.0
 * @date 2020/5/8
 */
@SuppressWarnings({"unchecked"})
public class VirtAcctServiceImpl implements VirtAcctService {

    /**
     * 虚拟账户开户接口
     * 交易状态以Result中布尔success为准，true为成功，false为失败
     * VirtAcctEstablishResponse 中应答码对应状态与Result中布尔success中匹配
     * 开户成功返回虚拟账户账号，失败不返回
     *
     * @param virtAcctEstablishRequest 虚拟账户开户请求
     * @return 虚拟账户开户交易结果
     */
    @Override
    public Result<VirtAcctEstablishResponse> virtAcctEstablish(VirtAcctEstablishRequest virtAcctEstablishRequest) {
        DubboService<VirtAcctEstablishRequest> dubboService = new DubboServiceImpl();
        Result<VirtAcctEstablishResponse> virtAcctEstablishResponseResult = new Result<>();
        try {
            if (!AcctTxnNumEnum.ESTABLISH.getTxnNum().equals(virtAcctEstablishRequest.getHeader().getTxnNum())) {
                throw new BizException(AcctRespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(),
                        AcctRespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
            }
            // 通过服务名调用相应的服务
            DubboResult<VirtAcctEstablishResponse> dubboResult = dubboService.callAtomService(virtAcctEstablishRequest,
                    AcctTxnNumEnum.ESTABLISH.getService(), VirtAcctEstablishResponse.class);
            virtAcctEstablishResponseResult.setResult(dubboResult.getResult());
            virtAcctEstablishResponseResult.setSuccess(dubboResult.isSuccess());
        } catch (Exception e) {
            VirtAcctEstablishResponse virtAcctEstablishResponse = new VirtAcctEstablishResponse();
            virtAcctEstablishResponseResult.setResult(virtAcctEstablishResponse);
            virtAcctEstablishResponse.setHeader(virtAcctEstablishRequest.getHeader());
            virtAcctEstablishResponseResult.setSuccess(false);
            if (e instanceof BizException) {
                virtAcctEstablishResponse.setRespCode(((BizException) e).getCode());
                virtAcctEstablishResponse.setRespDesc(e.getMessage());
            } else {
                virtAcctEstablishResponse.setRespCode(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespCode());
                virtAcctEstablishResponse.setRespDesc(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespDesc());
            }
        }

        return virtAcctEstablishResponseResult;
    }

    /**
     * 虚拟账户余额查询
     * 交易状态以Result中布尔success为准，true为成功，false为失败
     * VirtAcctBalanceQueryResponse 中应答码对应状态与Result中布尔success中匹配
     * 查询成功返回余额，查询失败不返回
     *
     * @param virtAcctBalanceQueryRequest 虚拟账户余额查询请求
     * @return 多商户记账交易结果
     */
    @Override
    public Result<VirtAcctBalanceQueryResponse> virtAcctBalanceQuery(VirtAcctBalanceQueryRequest virtAcctBalanceQueryRequest) {

        DubboService<VirtAcctBalanceQueryRequest> dubboService = new DubboServiceImpl();
        Result<VirtAcctBalanceQueryResponse> virtAcctBalanceQueryResponseResult = new Result<>();

        try {
            if (!AcctTxnNumEnum.BALANCE_QUERY.getTxnNum().equals(virtAcctBalanceQueryRequest.getHeader().getTxnNum())) {
                throw new BizException(AcctRespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(),
                        AcctRespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
            }
            // 通过服务名调用相应的服务
            DubboResult<VirtAcctBalanceQueryResponse> dubboResult = dubboService.callAtomService(
                    virtAcctBalanceQueryRequest, AcctTxnNumEnum.BALANCE_QUERY.getService(), VirtAcctBalanceQueryResponse.class);
            /* 拼装业务返回应答结构 */
            virtAcctBalanceQueryResponseResult.setResult(dubboResult.getResult());
            virtAcctBalanceQueryResponseResult.setSuccess(dubboResult.isSuccess());
        } catch (Exception e) {
            VirtAcctBalanceQueryResponse virtAcctBalanceQueryResponse = new VirtAcctBalanceQueryResponse();
            virtAcctBalanceQueryResponseResult.setResult(virtAcctBalanceQueryResponse);
            virtAcctBalanceQueryResponse.setHeader(virtAcctBalanceQueryRequest.getHeader());
            virtAcctBalanceQueryResponseResult.setSuccess(false);
            if (e instanceof BizException) {
                virtAcctBalanceQueryResponse.setRespCode(((BizException) e).getCode());
                virtAcctBalanceQueryResponse.setRespDesc(e.getMessage());
            } else {
                virtAcctBalanceQueryResponse.setRespCode(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespCode());
                virtAcctBalanceQueryResponse.setRespDesc(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespDesc());
            }
        }

        return virtAcctBalanceQueryResponseResult;
    }

    /**
     * 多商户记账
     * 交易状态以Result中布尔success为准，true为成功，false为失败
     * VirtAcctMultiMchntAdjustResponse 中应答码对应状态与Result中布尔success中匹配
     * 多商户记账为原子操作要不全部记账成功，要不全部记账失败
     *
     * @param virtAcctMultiMchntAdjustRequest 多商户记账请求其中记账明细为list
     * @return 多商户记账交易结果
     */
    @Override
    public Result<VirtAcctMultiMchntAdjustResponse> virtAcctMultiMchntAdjust(VirtAcctMultiMchntAdjustRequest virtAcctMultiMchntAdjustRequest) {

        DubboService<VirtAcctMultiMchntAdjustRequest> dubboService = new DubboServiceImpl();
        Result<VirtAcctMultiMchntAdjustResponse> virtAcctMultiMchntAdjustResponseResult = new Result<>();
        try {
            if (!AcctTxnNumEnum.MULTI_MCHNT_ADJUST.getTxnNum().equals(virtAcctMultiMchntAdjustRequest.getHeader().getTxnNum())) {
                throw new BizException(AcctRespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(),
                        AcctRespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
            }
            // 通过服务名调用相应的服务
            DubboResult<VirtAcctMultiMchntAdjustResponse> dubboResult = dubboService.callAtomService(virtAcctMultiMchntAdjustRequest,
                    AcctTxnNumEnum.MULTI_MCHNT_ADJUST.getService(), VirtAcctMultiMchntAdjustResponse.class);
            virtAcctMultiMchntAdjustResponseResult.setResult(dubboResult.getResult());
            virtAcctMultiMchntAdjustResponseResult.setSuccess(dubboResult.isSuccess());
        } catch (Exception e) {
            VirtAcctMultiMchntAdjustResponse virtAcctMultiMchntAdjustResponse = new VirtAcctMultiMchntAdjustResponse();
            virtAcctMultiMchntAdjustResponseResult.setResult(virtAcctMultiMchntAdjustResponse);
            virtAcctMultiMchntAdjustResponse.setHeader(virtAcctMultiMchntAdjustRequest.getHeader());
            virtAcctMultiMchntAdjustResponseResult.setSuccess(false);
            if (e instanceof BizException) {
                virtAcctMultiMchntAdjustResponse.setRespCode(((BizException) e).getCode());
                virtAcctMultiMchntAdjustResponse.setRespDesc(e.getMessage());
            } else {
                virtAcctMultiMchntAdjustResponse.setRespCode(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespCode());
                virtAcctMultiMchntAdjustResponse.setRespDesc(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespDesc());
            }
        }

        return virtAcctMultiMchntAdjustResponseResult;
    }

    /**
     * 虚拟账户预授权撤销交易
     * 交易状态以Result中布尔success为准，true为成功，false为失败
     * VirtAcctPreAuthCancelResponse 中应答码对应状态与Result中布尔success中匹配
     *
     * @param virtAcctPreAuthCancelRequest 上送原记账流水
     * @return 虚拟账户预授权撤销交易结果
     */
    @Override
    public Result<VirtAcctPreAuthCancelResponse> virtAcctPreAuthCancel(VirtAcctPreAuthCancelRequest virtAcctPreAuthCancelRequest) {

        DubboService<VirtAcctPreAuthCancelRequest> dubboService = new DubboServiceImpl();
        Result<VirtAcctPreAuthCancelResponse> virtAcctPreAuthCancelResponseResult = new Result<>();
        try {
            if (!AcctTxnNumEnum.PRE_AUTH_CANCEL.getTxnNum().equals(virtAcctPreAuthCancelRequest.getHeader().getTxnNum())) {
                throw new BizException(AcctRespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(),
                        AcctRespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
            }
            // 通过服务名调用相应的服务
            DubboResult<VirtAcctPreAuthCancelResponse> dubboResult = dubboService.callAtomService(virtAcctPreAuthCancelRequest,
                    AcctTxnNumEnum.PRE_AUTH_CANCEL.getService(), VirtAcctPreAuthCancelResponse.class);
            virtAcctPreAuthCancelResponseResult.setResult(dubboResult.getResult());
            virtAcctPreAuthCancelResponseResult.setSuccess(dubboResult.isSuccess());
        } catch (Exception e) {
            VirtAcctPreAuthCancelResponse virtAcctPreAuthCancelResponse = new VirtAcctPreAuthCancelResponse();
            virtAcctPreAuthCancelResponseResult.setResult(virtAcctPreAuthCancelResponse);
            virtAcctPreAuthCancelResponse.setHeader(virtAcctPreAuthCancelRequest.getHeader());
            virtAcctPreAuthCancelResponseResult.setSuccess(false);
            if (e instanceof BizException) {
                virtAcctPreAuthCancelResponse.setRespCode(((BizException) e).getCode());
                virtAcctPreAuthCancelResponse.setRespDesc(e.getMessage());
            } else {
                virtAcctPreAuthCancelResponse.setRespCode(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespCode());
                virtAcctPreAuthCancelResponse.setRespDesc(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespDesc());
            }
        }

        return virtAcctPreAuthCancelResponseResult;
    }

    /**
     * 虚拟账户预授权完成交易
     * 交易状态以Result中布尔success为准，true为成功，false为失败
     * VirtAcctPreAuthCompResponse 中应答码对应状态与Result中布尔success中匹配
     *
     * @param virtAcctPreAuthCompRequest 上送原预授权返回的记账流水
     * @return 虚拟账户预授权交易结果
     */
    @Override
    public Result<VirtAcctPreAuthCompResponse> virtAcctPreAuthComp(VirtAcctPreAuthCompRequest virtAcctPreAuthCompRequest) {

        DubboService<VirtAcctPreAuthCompRequest> dubboService = new DubboServiceImpl();
        Result<VirtAcctPreAuthCompResponse> virtAcctPreAuthCompResponseResult = new Result<>();
        try {
            if (!AcctTxnNumEnum.PRE_AUTH_COMP.getTxnNum().equals(virtAcctPreAuthCompRequest.getHeader().getTxnNum())) {
                throw new BizException(AcctRespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(),
                        AcctRespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
            }
            // 通过服务名调用相应的服务
            DubboResult<VirtAcctPreAuthCompResponse> dubboResult = dubboService.callAtomService(virtAcctPreAuthCompRequest,
                    AcctTxnNumEnum.PRE_AUTH_COMP.getService(), VirtAcctPreAuthCompResponse.class);
            virtAcctPreAuthCompResponseResult.setResult(dubboResult.getResult());
            virtAcctPreAuthCompResponseResult.setSuccess(dubboResult.isSuccess());
        } catch (Exception e) {
            VirtAcctPreAuthCompResponse virtAcctPreAuthCompResponse = new VirtAcctPreAuthCompResponse();
            virtAcctPreAuthCompResponseResult.setResult(virtAcctPreAuthCompResponse);
            virtAcctPreAuthCompResponse.setHeader(virtAcctPreAuthCompRequest.getHeader());
            virtAcctPreAuthCompResponseResult.setSuccess(false);
            if (e instanceof BizException) {
                virtAcctPreAuthCompResponse.setRespCode(((BizException) e).getCode());
                virtAcctPreAuthCompResponse.setRespDesc(e.getMessage());
            } else {
                virtAcctPreAuthCompResponse.setRespCode(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespCode());
                virtAcctPreAuthCompResponse.setRespDesc(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespDesc());
            }
        }

        return virtAcctPreAuthCompResponseResult;
    }

    /**
     * 虚拟账户预授权交易
     * 交易状态以Result中布尔success为准，true为成功，false为失败
     * VirtAcctPreAuthResponse 中应答码对应状态与Result中布尔success中匹配
     * 成功返回记账流水
     *
     * @param virtAcctPreAuthRequest 虚拟账户预授权请求
     * @return 虚拟账户预授权交易结果
     */
    @Override
    public Result<VirtAcctPreAuthResponse> virtAcctPreAuth(VirtAcctPreAuthRequest virtAcctPreAuthRequest) {

        DubboService<VirtAcctPreAuthRequest> dubboService = new DubboServiceImpl();
        Result<VirtAcctPreAuthResponse> virtAcctPreAuthResponseResult = new Result<>();
        try {
            if (!AcctTxnNumEnum.PRE_AUTH.getTxnNum().equals(virtAcctPreAuthRequest.getHeader().getTxnNum())) {
                throw new BizException(AcctRespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(),
                        AcctRespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
            }
            // 通过服务名调用相应的服务
            DubboResult<VirtAcctPreAuthResponse> dubboResult = dubboService.callAtomService(virtAcctPreAuthRequest,
                    AcctTxnNumEnum.PRE_AUTH.getService(), VirtAcctPreAuthResponse.class);
            virtAcctPreAuthResponseResult.setResult(dubboResult.getResult());
            virtAcctPreAuthResponseResult.setSuccess(dubboResult.isSuccess());
        } catch (Exception e) {
            VirtAcctPreAuthResponse virtAcctPreAuthResponse = new VirtAcctPreAuthResponse();
            virtAcctPreAuthResponseResult.setResult(virtAcctPreAuthResponse);
            virtAcctPreAuthResponse.setHeader(virtAcctPreAuthRequest.getHeader());
            virtAcctPreAuthResponseResult.setSuccess(false);
            if (e instanceof BizException) {
                virtAcctPreAuthResponse.setRespCode(((BizException) e).getCode());
                virtAcctPreAuthResponse.setRespDesc(e.getMessage());
            } else {
                virtAcctPreAuthResponse.setRespCode(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespCode());
                virtAcctPreAuthResponse.setRespDesc(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespDesc());
            }
        }

        return virtAcctPreAuthResponseResult;
    }

    /**
     * 虚拟账户单笔记账
     * 交易状态以Result中布尔success为准，true为成功，false为失败
     * VirtAcctSingleAdjustResponse 中应答码对应状态与Result中布尔success中匹配
     *
     * @param virtAcctSingleAdjustRequest 支持借贷两个方向需要请求指定
     * @return 虚拟账户单笔记账交易结果
     */
    @Override
    public Result<VirtAcctSingleAdjustResponse> virtAcctSingleAdjust(VirtAcctSingleAdjustRequest virtAcctSingleAdjustRequest) {

        DubboService<VirtAcctSingleAdjustRequest> dubboService = new DubboServiceImpl();
        Result<VirtAcctSingleAdjustResponse> virtAcctSingleAdjustResponseResult = new Result<>();
        try {
            if (!AcctTxnNumEnum.SINGLE_ADJUST.getTxnNum().equals(virtAcctSingleAdjustRequest.getHeader().getTxnNum())) {
                throw new BizException(AcctRespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(),
                        AcctRespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
            }
            // 通过服务名调用相应的服务
            DubboResult<VirtAcctSingleAdjustResponse> dubboResult = dubboService.callAtomService(virtAcctSingleAdjustRequest,
                    AcctTxnNumEnum.SINGLE_ADJUST.getService(), VirtAcctSingleAdjustResponse.class);
            virtAcctSingleAdjustResponseResult.setResult(dubboResult.getResult());
            virtAcctSingleAdjustResponseResult.setSuccess(dubboResult.isSuccess());
        } catch (Exception e) {
            VirtAcctSingleAdjustResponse virtAcctSingleAdjustResponse = new VirtAcctSingleAdjustResponse();
            virtAcctSingleAdjustResponseResult.setResult(virtAcctSingleAdjustResponse);
            virtAcctSingleAdjustResponse.setHeader(virtAcctSingleAdjustRequest.getHeader());
            virtAcctSingleAdjustResponseResult.setSuccess(false);
            if (e instanceof BizException) {
                virtAcctSingleAdjustResponse.setRespCode(((BizException) e).getCode());
                virtAcctSingleAdjustResponse.setRespDesc(e.getMessage());
            } else {
                virtAcctSingleAdjustResponse.setRespCode(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespCode());
                virtAcctSingleAdjustResponse.setRespDesc(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespDesc());
            }
        }

        return virtAcctSingleAdjustResponseResult;
    }

    /**
     * 虚拟账户单笔交易明细查询
     * 查询交易状态以Result中布尔success为准，true为成功存在应答，，false为失败
     *
     * @param virtAcctSingleTransDetailQueryRequest 上送原记账流水
     * @return 虚拟账户单笔交易明细查询结果
     */
    @Override
    public Result<VirtAcctSingleTransDetailQueryResponse> virtAcctSingleTransDetailQuery(
            VirtAcctSingleTransDetailQueryRequest virtAcctSingleTransDetailQueryRequest) {

        DubboService<VirtAcctSingleTransDetailQueryRequest> dubboService = new DubboServiceImpl();
        Result<VirtAcctSingleTransDetailQueryResponse> virtAcctSingleTransDetailQueryResponseResult = new Result<>();
        try {
            if (!AcctTxnNumEnum.SINGLE_TRANS_DETAIL.getTxnNum().equals(virtAcctSingleTransDetailQueryRequest.getHeader().getTxnNum())) {
                throw new BizException(AcctRespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(),
                        AcctRespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
            }
            // 通过服务名调用相应的服务
            DubboResult<VirtAcctSingleTransDetailQueryResponse> dubboResult = dubboService.callAtomService(
                    virtAcctSingleTransDetailQueryRequest, AcctTxnNumEnum.SINGLE_TRANS_DETAIL.getService(),
                    VirtAcctSingleTransDetailQueryResponse.class);
            virtAcctSingleTransDetailQueryResponseResult.setResult(dubboResult.getResult());
            virtAcctSingleTransDetailQueryResponseResult.setSuccess(dubboResult.isSuccess());
        } catch (Exception e) {
            VirtAcctSingleTransDetailQueryResponse virtAcctSingleTransDetailQueryResponse = new VirtAcctSingleTransDetailQueryResponse();
            virtAcctSingleTransDetailQueryResponseResult.setResult(virtAcctSingleTransDetailQueryResponse);
            virtAcctSingleTransDetailQueryResponse.setHeader(virtAcctSingleTransDetailQueryRequest.getHeader());
            virtAcctSingleTransDetailQueryResponseResult.setSuccess(false);
            if (e instanceof BizException) {
                virtAcctSingleTransDetailQueryResponse.setRespCode(((BizException) e).getCode());
                virtAcctSingleTransDetailQueryResponse.setRespDesc(e.getMessage());
            } else {
                virtAcctSingleTransDetailQueryResponse.setRespCode(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespCode());
                virtAcctSingleTransDetailQueryResponse.setRespDesc(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespDesc());
            }
        }

        return virtAcctSingleTransDetailQueryResponseResult;
    }

    /**
     * 虚拟账户账户状态修改
     * 修改交易状态以Result中布尔success为准，true为成功，false为失败
     * VirtAcctStatusChangeResponse中应答码对应状态与Result中布尔success中匹配
     *
     * @param virtAcctStatusChangeRequest 是否保留客户信息需指定
     * @return 虚拟账户状态修改结果
     */
    @Override
    public Result<VirtAcctStatusChangeResponse> virtAcctStatusChange(VirtAcctStatusChangeRequest virtAcctStatusChangeRequest) {

        DubboService<VirtAcctStatusChangeRequest> dubboService = new DubboServiceImpl();
        Result<VirtAcctStatusChangeResponse> virtAcctStatusChangeResponseResult = new Result<>();
        try {
            if (!AcctTxnNumEnum.STATUS_CHANGE.getTxnNum().equals(virtAcctStatusChangeRequest.getHeader().getTxnNum())) {
                throw new BizException(AcctRespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(),
                        AcctRespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
            }
            // 通过服务名调用相应的服务
            DubboResult<VirtAcctStatusChangeResponse> dubboResult = dubboService.callAtomService(virtAcctStatusChangeRequest,
                    AcctTxnNumEnum.STATUS_CHANGE.getService(), VirtAcctEstablishResponse.class);
            virtAcctStatusChangeResponseResult.setResult(dubboResult.getResult());
            virtAcctStatusChangeResponseResult.setSuccess(dubboResult.isSuccess());
        } catch (Exception e) {
            VirtAcctStatusChangeResponse virtAcctStatusChangeResponse = new VirtAcctStatusChangeResponse();
            virtAcctStatusChangeResponseResult.setResult(virtAcctStatusChangeResponse);
            virtAcctStatusChangeResponse.setHeader(virtAcctStatusChangeRequest.getHeader());
            virtAcctStatusChangeResponseResult.setSuccess(false);
            if (e instanceof BizException) {
                virtAcctStatusChangeResponse.setRespCode(((BizException) e).getCode());
                virtAcctStatusChangeResponse.setRespDesc(e.getMessage());
            } else {
                virtAcctStatusChangeResponse.setRespCode(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespCode());
                virtAcctStatusChangeResponse.setRespDesc(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespDesc());
            }
        }

        return virtAcctStatusChangeResponseResult;
    }

    /**
     * 虚拟账户交易明细查询
     * 查询交易状态以Result中布尔success为准，true为成功，false为失败
     * 成功则返回查询条件指定的交易明细
     *
     * @param virtAcctTransDetailQueryRequest 支持日期起止时间的所有交易明细查询，
     *                                        支持分页每页记录数及当前需要查询的页数需指定
     * @return 虚拟账户交易明细查询应答
     */
    @Override
    public Result<VirtAcctTransDetailQueryResponse> virtAcctTransDetailQuery(VirtAcctTransDetailQueryRequest virtAcctTransDetailQueryRequest) {

        DubboService<VirtAcctTransDetailQueryRequest> dubboService = new DubboServiceImpl();
        Result<VirtAcctTransDetailQueryResponse> virtAcctTransDetailQueryResponseResult = new Result<>();
        try {
            if (!AcctTxnNumEnum.TRANS_DETAIL_QUERY.getTxnNum().equals(virtAcctTransDetailQueryRequest.getHeader().getTxnNum())) {
                throw new BizException(AcctRespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(),
                        AcctRespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
            }
            // 通过服务名调用相应的服务
            DubboResult<VirtAcctTransDetailQueryResponse> dubboResult = dubboService.callAtomService(virtAcctTransDetailQueryRequest,
                    AcctTxnNumEnum.TRANS_DETAIL_QUERY.getService(), VirtAcctTransDetailQueryResponse.class);
            virtAcctTransDetailQueryResponseResult.setResult(dubboResult.getResult());
            virtAcctTransDetailQueryResponseResult.setSuccess(dubboResult.isSuccess());
        } catch (Exception e) {
            VirtAcctTransDetailQueryResponse virtAcctTransDetailQueryResponse = new VirtAcctTransDetailQueryResponse();
            virtAcctTransDetailQueryResponseResult.setResult(virtAcctTransDetailQueryResponse);
            virtAcctTransDetailQueryResponse.setHeader(virtAcctTransDetailQueryRequest.getHeader());
            virtAcctTransDetailQueryResponseResult.setSuccess(false);
            if (e instanceof BizException) {
                virtAcctTransDetailQueryResponse.setRespCode(((BizException) e).getCode());
                virtAcctTransDetailQueryResponse.setRespDesc(e.getMessage());
            } else {
                virtAcctTransDetailQueryResponse.setRespCode(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespCode());
                virtAcctTransDetailQueryResponse.setRespDesc(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespDesc());
            }
        }

        return virtAcctTransDetailQueryResponseResult;
    }

    /**
     * 虚拟账户交易状态查询
     * 查询交易本身状态以Result中布尔success为准，true为成功，false为失败
     * 业务的状态需要在VirtAcctTransStatusQueryResponse中判断
     *
     * @param virtAcctTransStatusQueryRequest 上送原记账流水
     * @return 虚拟账户查询应答结果
     */
    @Override
    public Result<VirtAcctTransStatusQueryResponse> virtAcctTransStatusQuery(VirtAcctTransStatusQueryRequest virtAcctTransStatusQueryRequest) {

        DubboService<VirtAcctTransStatusQueryRequest> dubboService = new DubboServiceImpl();
        Result<VirtAcctTransStatusQueryResponse> virtAcctTransStatusQueryResponseResult = new Result<>();
        try {
            if (!AcctTxnNumEnum.TRANS_STATUS_QUERY.getTxnNum().equals(virtAcctTransStatusQueryRequest.getHeader().getTxnNum())) {
                throw new BizException(AcctRespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(),
                        AcctRespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
            }
            // 通过服务名调用相应的服务
            DubboResult<VirtAcctTransStatusQueryResponse> dubboResult = dubboService.callAtomService(virtAcctTransStatusQueryRequest,
                    AcctTxnNumEnum.TRANS_STATUS_QUERY.getService(), VirtAcctTransStatusQueryResponse.class);
            virtAcctTransStatusQueryResponseResult.setResult(dubboResult.getResult());
            virtAcctTransStatusQueryResponseResult.setSuccess(dubboResult.isSuccess());
        } catch (Exception e) {
            VirtAcctTransStatusQueryResponse virtAcctTransStatusQueryResponse = new VirtAcctTransStatusQueryResponse();
            virtAcctTransStatusQueryResponseResult.setResult(virtAcctTransStatusQueryResponse);
            virtAcctTransStatusQueryResponse.setHeader(virtAcctTransStatusQueryRequest.getHeader());
            virtAcctTransStatusQueryResponseResult.setSuccess(false);
            if (e instanceof BizException) {
                virtAcctTransStatusQueryResponse.setRespCode(((BizException) e).getCode());
                virtAcctTransStatusQueryResponse.setRespDesc(e.getMessage());
            } else {
                virtAcctTransStatusQueryResponse.setRespCode(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespCode());
                virtAcctTransStatusQueryResponse.setRespDesc(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespDesc());
            }
        }

        return virtAcctTransStatusQueryResponseResult;
    }

    /**
     * 多商户预授权
     * 交易状态以Result中布尔success为准，true为成功，false为失败
     * VirtAcctMultiMchntPreAuthResponse 中应答码对应状态与Result中布尔success中匹配
     * 多商户记账为原子操作要不全部预授权成功，要不全部预授权失败
     *
     * @param virtAcctMultiMchntPreAuthRequest 多商户记账请求其中记账明细为list
     * @return 多商户预授权交易结果
     */
    @Override
    public Result<VirtAcctMultiMchntPreAuthResponse> virtAcctMultiMchntPreAuth(VirtAcctMultiMchntPreAuthRequest virtAcctMultiMchntPreAuthRequest) {

        DubboService<VirtAcctMultiMchntPreAuthRequest> dubboService = new DubboServiceImpl();
        Result<VirtAcctMultiMchntPreAuthResponse> virtAcctMultiMchntPreAuthResponseResult = new Result<>();
        try {
            if (!AcctTxnNumEnum.MULT_MCHNT_PRE_AUTH.getTxnNum().equals(virtAcctMultiMchntPreAuthRequest.getHeader().getTxnNum())) {
                throw new BizException(AcctRespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(),
                        AcctRespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
            }
            // 通过服务名调用相应的服务
            DubboResult<VirtAcctMultiMchntPreAuthResponse> dubboResult = dubboService.callAtomService(virtAcctMultiMchntPreAuthRequest,
                    AcctTxnNumEnum.MULT_MCHNT_PRE_AUTH.getService(), VirtAcctMultiMchntPreAuthResponse.class);
            virtAcctMultiMchntPreAuthResponseResult.setResult(dubboResult.getResult());
            virtAcctMultiMchntPreAuthResponseResult.setSuccess(dubboResult.isSuccess());
        } catch (Exception e) {
            VirtAcctMultiMchntPreAuthResponse virtAcctMultiMchntPreAuthResponse = new VirtAcctMultiMchntPreAuthResponse();
            virtAcctMultiMchntPreAuthResponseResult.setResult(virtAcctMultiMchntPreAuthResponse);
            virtAcctMultiMchntPreAuthResponse.setHeader(virtAcctMultiMchntPreAuthRequest.getHeader());
            virtAcctMultiMchntPreAuthResponseResult.setSuccess(false);
            if (e instanceof BizException) {
                virtAcctMultiMchntPreAuthResponse.setRespCode(((BizException) e).getCode());
                virtAcctMultiMchntPreAuthResponse.setRespDesc(e.getMessage());
            } else {
                virtAcctMultiMchntPreAuthResponse.setRespCode(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespCode());
                virtAcctMultiMchntPreAuthResponse.setRespDesc(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespDesc());
            }
        }

        return virtAcctMultiMchntPreAuthResponseResult;
    }

    /**
     * 多商户预授权撤销
     * 多商户预授权撤销为原子操作要不全部预授权撤销成功，要不全部预授权撤销失败
     * 交易状态以Result中布尔success为准，true为成功，false为失败
     * VirtAcctMultiMchntPreAuthCancelResponse 中应答码对应状态与Result中布尔success中匹配
     *
     * @param virtAcctMultiMchntPreAuthCancelRequest 多商户记账请求其中记账明细为list
     * @return 多商户预授权撤销交易结果
     */
    @Override
    public Result<VirtAcctMultiMchntPreAuthCancelResponse> virtAcctMultiMchntPreAuthCancel(VirtAcctMultiMchntPreAuthCancelRequest virtAcctMultiMchntPreAuthCancelRequest) {

        DubboService<VirtAcctMultiMchntPreAuthCancelRequest> dubboService = new DubboServiceImpl();
        Result<VirtAcctMultiMchntPreAuthCancelResponse> virtAcctMultiMchntPreAuthCancelResponseResult = new Result<>();
        try {
            if (!AcctTxnNumEnum.MULT_MCHNT_PRE_AUTH_CANCEL.getTxnNum().equals(virtAcctMultiMchntPreAuthCancelRequest.getHeader().getTxnNum())) {
                throw new BizException(AcctRespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(),
                        AcctRespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
            }
            // 通过服务名调用相应的服务
            DubboResult<VirtAcctMultiMchntPreAuthCancelResponse> dubboResult = dubboService.callAtomService(virtAcctMultiMchntPreAuthCancelRequest,
                    AcctTxnNumEnum.MULT_MCHNT_PRE_AUTH_CANCEL.getService(), VirtAcctMultiMchntPreAuthCancelResponse.class);
            virtAcctMultiMchntPreAuthCancelResponseResult.setResult(dubboResult.getResult());
            virtAcctMultiMchntPreAuthCancelResponseResult.setSuccess(dubboResult.isSuccess());
        } catch (Exception e) {
            VirtAcctMultiMchntPreAuthCancelResponse virtAcctMultiMchntPreAuthCancelResponse = new VirtAcctMultiMchntPreAuthCancelResponse();
            virtAcctMultiMchntPreAuthCancelResponseResult.setResult(virtAcctMultiMchntPreAuthCancelResponse);
            virtAcctMultiMchntPreAuthCancelResponse.setHeader(virtAcctMultiMchntPreAuthCancelRequest.getHeader());
            virtAcctMultiMchntPreAuthCancelResponseResult.setSuccess(false);
            if (e instanceof BizException) {
                virtAcctMultiMchntPreAuthCancelResponse.setRespCode(((BizException) e).getCode());
                virtAcctMultiMchntPreAuthCancelResponse.setRespDesc(e.getMessage());
            } else {
                virtAcctMultiMchntPreAuthCancelResponse.setRespCode(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespCode());
                virtAcctMultiMchntPreAuthCancelResponse.setRespDesc(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespDesc());
            }
        }

        return virtAcctMultiMchntPreAuthCancelResponseResult;
    }

    /**
     * 多商户预授权完成
     * 交易状态以Result中布尔success为准，true为成功，false为失败
     * VirtAcctMultiMchntPreAuthCompResponse 中应答码对应状态与Result中布尔success中匹配
     * 多商户预授权完成为原子操作要不全部预授权完成成功，要不全部预授权完成失败
     *
     * @param virtAcctMultiMchntPreAuthCompRequest 多商户记账请求其中记账明细为list
     * @return 多商户预授权撤销交易结果
     */
    @Override
    public Result<VirtAcctMultiMchntPreAuthCompResponse> virtAcctMultiMchntPreAuthComp(VirtAcctMultiMchntPreAuthCompRequest virtAcctMultiMchntPreAuthCompRequest) {

        DubboService<VirtAcctMultiMchntPreAuthCompRequest> dubboService = new DubboServiceImpl();
        Result<VirtAcctMultiMchntPreAuthCompResponse> virtAcctMultiMchntPreAuthCompResponseResult = new Result<>();
        try {
            if (!AcctTxnNumEnum.MULT_MCHNT_PRE_AUTH_COMP.getTxnNum().equals(virtAcctMultiMchntPreAuthCompRequest.getHeader().getTxnNum())) {
                throw new BizException(AcctRespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(),
                        AcctRespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
            }
            // 通过服务名调用相应的服务
            DubboResult<VirtAcctMultiMchntPreAuthCompResponse> dubboResult = dubboService.callAtomService(virtAcctMultiMchntPreAuthCompRequest,
                    AcctTxnNumEnum.MULT_MCHNT_PRE_AUTH_COMP.getService(), VirtAcctMultiMchntPreAuthCompResponse.class);
            virtAcctMultiMchntPreAuthCompResponseResult.setResult(dubboResult.getResult());
            virtAcctMultiMchntPreAuthCompResponseResult.setSuccess(dubboResult.isSuccess());
        } catch (Exception e) {
            VirtAcctMultiMchntPreAuthCompResponse virtAcctMultiMchntPreAuthCompResponse = new VirtAcctMultiMchntPreAuthCompResponse();
            virtAcctMultiMchntPreAuthCompResponseResult.setResult(virtAcctMultiMchntPreAuthCompResponse);
            virtAcctMultiMchntPreAuthCompResponse.setHeader(virtAcctMultiMchntPreAuthCompRequest.getHeader());
            virtAcctMultiMchntPreAuthCompResponseResult.setSuccess(false);
            if (e instanceof BizException) {
                virtAcctMultiMchntPreAuthCompResponse.setRespCode(((BizException) e).getCode());
                virtAcctMultiMchntPreAuthCompResponse.setRespDesc(e.getMessage());
            } else {
                virtAcctMultiMchntPreAuthCompResponse.setRespCode(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespCode());
                virtAcctMultiMchntPreAuthCompResponse.setRespDesc(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespDesc());
            }
        }

        return virtAcctMultiMchntPreAuthCompResponseResult;
    }
}
